﻿using System;
using System.Collections.Generic;
using NailsFramework.Persistence;
using CID.Domain.Development;

namespace CID.Domain.Infrastructure
{
    public class PackageType : Model<PackageType>, IPackageType
    {
        public virtual int Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
        public virtual bool Enabled { get; set; }

        private IList<IPackage> packages = new List<IPackage>();
        public virtual IEnumerable<IPackage> Packages { get { return packages; } }

        protected PackageType()
        {
            Enabled = true;
        }

        public PackageType(string name, string description) : this()
        {
            Name = name;
            Description = description;
        }

        public virtual IPackage CreatePackage(IVersion version, byte[] content, string comment, bool active = false)
        {
            var result = new Package(this, version, content, comment);
            packages.Add(result);
            if (active) version.SetActivePackage(result);
            return result;
        }
    }
}
